home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
answrbok
/
5_5.lha
/
5_5
/
5_5a_all.c
next >
Wrap
C/C++ Source or Header
|
1993-08-08
|
2KB
|
109 lines
* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
* The C++ Answer Book */
* Tony Hansen */
* All rights reserved. */
include <stream.h>
include <string.h>
include <ctype.h>
include <debug.h>
nt error(const char *fmt ...);
har prefix[512] = "....", *endprefix = &prefix[1];
har *incr()
*endprefix++ = '.';
*endprefix = '\0';
return prefix+1;
har *decr()
*--endprefix = '\0';
return prefix;
har *unctrl(unsigned int c)
static char x[5];
char *p = x;
if (c > 0177)
*p++ = 'M', *p++ = '-', c -= 0200;
if ((c < 040) || (c == 0177))
*p++ = '^', *p++ = c ^ 0100;
else
*p++ = c;
*p = '\0';
return x;
include "5_5A.h" /* enum exprtype */
include "5_5B.h" /* class tree, expr, token */
include "5_5a0.c" /* forward declarations */
include "5_5a5.c" /* prim() */
include "5_5a4.c" /* term() */
include "5_5a3.c" /* get_expr() */
include "5_5a2.c" /* gettoken() */
include "5_5a1.c" /* expandtree, expr::expr() */
include "5_5b2.c" /* treeval() */
include "5_5b1.c" /* expr::eval() */
include "main.c"
/ print the expression tree
tatic char *spaces(int num)
return form("%.*s", num * 3, " ");
oid tree::print(int level)
if (this)
switch (this->type)
{
case PLUS:
case DIV:
case MUL:
cout << spaces(level) << chr(this->type) << "\n";
this->left->print(level + 1);
this->right->print(level + 1);
return;
case MINUS:
cout << spaces(level) << chr(this->type) << "\n";
if (this->right)
{
this->left->print(level + 1);
this->right->print(level + 1);
}
else
this->left->print(level + 1);
return;
case NUMBER:
cout << spaces(level) << "# " << this->value << "\n";
return;
case LP:
cout << spaces(level) << chr(this->type) << "\n";
this->left->print(level + 1);
return;
case RP:
case END:
default:
cout << spaces(level) << chr(this->type) << "\n";
error("invalid type within tree");
break;
}
else
error("NULL node found");
return;
oid expr::eprint()
if (debug) head->print(0); }